<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/24 0024
 * Time: 11:46
 */
$dom = new  DOMDocument();

$html = $dom->createElement('html');
$html->setAttribute('xmlns', "http://www.w3.org/1999/xhtml");
$html->setAttribute('xml:lang', 'en');
$html->setAttribute('lang', "en");
$dom->appendChild($html);
$head = $dom->createElement('head');
$html->appendChild($head);
$title = $dom->createElement('title');
$title->appendChild($dom->createTextNode('XML Example'));
$head->appendChild($title);
$body = $dom->createElement('body');
$body->setAttribute('background', 'bg,png');
$html->appendChild($body);
$p = $dom->createElement('p');
$body->appendChild($p);
$text = $dom->createTextNode('Moved to');
$p->appendChild($text);

$a = $dom->createElement('a');
$a->setAttribute('href', 'http://example.org/');
$p->appendChild($a);
$text = $dom->createTextNode('.');
$p->appendChild($text);
$br = $dom->createElement('br');
$p->appendChild($br);
$text = $dom->createTextNode('foo & bar');
$p->appendChild($text);
$xml = $dom->saveXML();
//file_put_contents('create_dom.xml',$xml);
$fp = fopen('create_dom2.xml','a+');
fwrite($fp,$xml);
fclose($fp);